home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 176-200 / scopedisk189 / assignx / assignx.c < prev    next >
C/C++ Source or Header  |  1995-03-19  |  3KB  |  127 lines

  1. /************************************************************************/
  2. /*  EasyRequest trapper - deals with requests for nonexistant volumes   */
  3. /*                        V1.0, by Steve Tibbett                        */
  4. /************************************************************************/
  5. #include <Stdio.h>
  6. #include <libraries/gadtools.h>
  7. #include <intuition/intuition.h>
  8. #include <proto/gadtools.h>
  9. #include <proto/asl.h>
  10. #include <proto/exec.h>
  11. #include <proto/dos.h>
  12. #include <dos/dos.h>
  13. #include <exec/memory.h>
  14. #include <string.h>
  15. #include <ctype.h>
  16.  
  17. struct Library *IntuitionBase;
  18. struct Library *AslBase;
  19. struct Remember *Remember;
  20.  
  21. void MemCleanup(void) { }
  22.  
  23. struct AbortedList 
  24.     {
  25.     struct AbortedList *Next;
  26.     char Name[1];
  27.     } *AbortedList;
  28.  
  29. void *OrigFunc;
  30.  
  31. /************************************************************************/
  32. /*                        The new "EasyRequest"                         */
  33. /************************************************************************/
  34. int __saveds __interrupt __asm
  35. NewFunc(register __a0 struct Window *Win, register __a1 struct EasyStruct *EZ, 
  36. register __a2 ULONG *idcmp, register __a3 ULONG *args)
  37. {
  38. int Res;
  39. int Mine=0;
  40.  
  41. if (strcmp((char *)args[0], "Please insert volume")==0)
  42.     {
  43.     struct AbortedList *AL=AbortedList;
  44.  
  45.     while (AL)
  46.         {
  47.         if (stricmp((char *)AL->Name, (char *)args[1])==0)
  48.             return(0);
  49.  
  50.         AL=AL->Next;
  51.         };
  52.  
  53.     EZ->es_GadgetFormat="Retry|Assign|Cancel Forever|Cancel";
  54.     Mine=1;
  55.     };
  56.  
  57. Res=MyFunc(Win, EZ, idcmp, args);
  58.  
  59. if (Mine)
  60.     {
  61.     switch (Res)
  62.         {
  63.         case 2:
  64.             {
  65.             BPTR AsnLock;
  66.             char buff[80];
  67.             char *FullName;
  68.             struct FileRequester *FR;
  69.             
  70.             strcpy(buff, "Assignment for '");
  71.             strcat(buff, (char *)args[1]);
  72.             strcat(buff, "':");
  73.  
  74.             FR=(struct FileRequester *)AslFileRequest(Win, buff, "RAM:", "", 0, &FullName);
  75.             if (FR) {
  76.                 AsnLock=Lock(FullName, ACCESS_READ);
  77.                 if (AsnLock)
  78.                     AssignLock((char *)args[1], AsnLock);                    
  79.  
  80.                 FreeVec(FullName);
  81.                 FreeFileRequest(FR);
  82.                 };
  83.             return(1);
  84.             break;
  85.             };
  86.         case 3:
  87.             {
  88.             struct AbortedList *AL=(struct AbortedList *)AllocRemember(&Remember, strlen((char *)args[1])+sizeof(struct AbortedList)+2, MEMF_CLEAR);
  89.             if (AL) {
  90.                 strcpy(AL->Name, (char *)args[1]);
  91.                 AL->Next=AbortedList;
  92.                 AbortedList=AL;
  93.                 };
  94.             };
  95.         };
  96.     };
  97.  
  98. return(Res);
  99. }
  100.  
  101.  
  102. main()
  103. {
  104. void *OurVec;
  105.  
  106. IntuitionBase=OpenLibrary("intuition.library", 36);
  107. AslBase=OpenLibrary("asl.library", 36);
  108. if (IntuitionBase==0 || AslBase==0)
  109.     return(10);
  110.  
  111. OrigFunc=SetFunction(IntuitionBase, -0x24c, NewFunc);
  112. if (OrigFunc==0) 
  113.     return(15);
  114.  
  115. Wait(SIGBREAKF_CTRL_C);
  116.  
  117. OurVec=SetFunction(IntuitionBase, -0x24c, OrigFunc);
  118.  
  119. if (OurVec!=NewFunc)
  120.     EasyRequester(NULL, "AssignX Request", "Error removing wedge!\nReboot soon!", "Okay");
  121.  
  122. FreeRemember(&Remember, TRUE);
  123. CloseLibrary(IntuitionBase);
  124. CloseLibrary(AslBase);
  125. return(0);
  126. }
  127.